{extend name="common/main"}

{block name="css"}
<style>
    .lai{
        float: none;
        display:inline-block;
    }
</style>
{/block}

{block name="body"}
<body data-type="widgets">
{include file="common/index"}
<div class="tpl-content-wrapper">
    <div class="row-content am-cf">
        <div class="row">
            <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
                <!--<h3>点数转让</h3>-->
                <div class="widget am-cf">
                    <div class="widget-head am-cf">
                        <div class="widget-title  am-cf">设备{notempty name='$data'}编辑{else}新增{/notempty}</div>
                    </div>
                    <div class="widget-body am-fr">

                        <form class="am-form tpl-form-border-form tpl-form-border-br " form="submit" id="form" >
                            <div class="am-form-group">
                                <label for="user-weibo" class="am-u-sm-2">输入设备名(昵称): </label>
                                <div class="am-u-sm-3 lai">
                                    <input type="text"  name="nickname" placeholder="请输入设备昵称" value="{notempty name='$data'}{$data.nickname}{/notempty}">
                                    {notempty name='$data'}<input type="hidden"  name="id"  value="{$data.id}">{/notempty}
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label for="user-weibo" class="am-u-sm-2">输入设备号: </label>
                                <div class="am-u-sm-3 lai">
                                    <input type="text"  name="name" placeholder="请输入设备号" value="{notempty name='$data'}{$data.name}{/notempty}">
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label for="user-weibo" class="am-u-sm-2">设备初始试用时间:</label>
                                <div class="am-u-sm-3 lai">
                                    <input type="text"  placeholder="设备初始试用时间" data-am-datepicker  id="my-start-2" name="expire_time" value="{notempty name='$data'}{$data.expire_time|date='Y-m-d',###}{/notempty}"/>
                                </div>
                            </div>
                            <button type="submit" class="am-btn am-btn-primary am-radius" style=" padding: .3em 1em;">确定</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>


    </div>
</div>
</div>
</body>
{/block}

{block name="js"}
{include file='common:validation'}
<script src="/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<script>
    $(function(){

        var nowTemp = new Date();
        var nowDay = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0).valueOf();
        var nowMoth = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), 1, 0, 0, 0, 0).valueOf();
        var nowYear = new Date(nowTemp.getFullYear(), 0, 1, 0, 0, 0, 0).valueOf();
        var $myStart2 = $('#my-start-2');

        var checkin = $myStart2.datepicker({
            onRender: function(date, viewMode) {
                // 默认 days 视图，与当前日期比较
                var viewDate = nowDay;

                switch (viewMode) {
                    // moths 视图，与当前月份比较
                    case 1:
                        viewDate = nowMoth;
                        break;
                    // years 视图，与当前年份比较
                    case 2:
                        viewDate = nowYear;
                        break;
                }

                return date.valueOf() < viewDate ? 'am-disabled' : '';
            }
        }).on('changeDate.datepicker.amui', function(ev) {
            if (ev.date.valueOf() > checkout.date.valueOf()) {
                var newDate = new Date(ev.date)
                newDate.setDate(newDate.getDate() + 1);
                checkout.setValue(newDate);
            }
            checkin.close();
        }).data('amui.datepicker');





    });

</script>
<script type="text/javascript">

    //提交
    function roleSubmit(){

        var form=document.getElementById("form");
        var formData=new FormData(form);
        $.ajax({
            url:"{:Url('addData')}",
            type:'POST',
            data:formData,
            async: false,
            cache: false,
            contentType: false, //不设置内容类型
            processData: false, //不处理数据
            success:function(res){
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 2000,icon: 2});
                    return false;
                }
                layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 1}, function(){
                    window.location.href=document.referrer;


                });
            }
        });
    }
</script>
{/block}